import React from 'react'
import ReactDOM from 'react-dom'
import thunk from 'redux-thunk'
import { Provider } from 'react-redux'
import { createStore, applyMiddleware, compose } from 'redux'

import RouterMap from '@/router/routerMap'
import rootReducer from '@/redux'

import 'static/style'
import 'static/init'

// redux store
const store = createStore(rootReducer, compose(
	applyMiddleware(thunk),
	window.devToolsExtension ? window.devToolsExtension() : f=>f
))

ReactDOM.render(
	<Provider store={store}>
		<RouterMap/>
	</Provider>,
    document.querySelector('#root')
)

// Service Worker 生产环境打包生效
if(process.env.NODE_ENV==='production'){
    //service worker
    if ('serviceWorker' in navigator) {
        window.addEventListener('load', () => {
            navigator.serviceWorker.register('./service-worker.js').then(registration => {
                console.log('SW registered: ', registration)
            }).catch(registrationError => {
                console.log('SW registration failed: ', registrationError)
            })
        })
    }
}